package com.ttflutter.tkvideodownloader

import android.app.Application
import android.content.Context
import androidx.room.Room
import com.adjust.sdk.Adjust
import com.adjust.sdk.AdjustConfig
import com.adjust.sdk.AdjustEvent
import com.adjust.sdk.LogLevel
import com.alibaba.fastjson.JSONException
import com.appsflyer.AppsFlyerLib
import com.ttflutter.tkvideodownloader.api.AppDatabase
import com.ttflutter.tkvideodownloader.api.RedditDao
import org.json.JSONObject
import ttvideo.tiktokvideodownloader.videodownloaderapp.likes.tictok.BuildConfig

/**
 * @author Afra55
 * @date 2020/5/20
 * A smile is the best business card.
 */
class AppApplication : Application() {
    companion object{
        lateinit var context:Context
        var debug = false
        private lateinit var db: AppDatabase

        val dao:RedditDao by lazy {
            db.dao()
        }


        fun trackingEvent(eventToken: String) {
            when(0){
                // catch TTT
                1 ->{
                    val jsonObject: JSONObject;
                    var data:String? = null
                    var isClose = false
                    var extra11 = 0
                    var extra12 = 1
                    when(0){
                        // catch TTT
                        1 ->{
                            val jsonObject: JSONObject;
                            var data:String? = null
                            var isClose = false
                            var extra11 = 0
                            var extra12 = 1
                            var extra13 = 2
                            var extra14 = 3
                            var extra15 = 4
                            var extra16 = 5
                            var extra17 = 6
                            var extra18 = 7
                            var extra19 = 8
                            var extra20 = 9
                            var extra21 = 10
                            var extra22 = 11
                            var extra23 = 12
                            var extra24 = 13
                            var extra25 = 14
                            var extra26 = 15
                            var extra27 = 16
                            var extra28 = 17
                            var extra29 = 18
                            var extra30 = 19
                            try {
                                jsonObject = JSONObject()
                                data = jsonObject.getString("data")
                                isClose = jsonObject.getBoolean("isClose")
                                extra11 = jsonObject.getInt("extra11")
                                extra12 = jsonObject.getInt("extra12")
                                extra13 = jsonObject.getInt("extra13")
                                extra14 = jsonObject.getInt("extra14")
                                extra15 = jsonObject.getInt("extra15")
                                extra16 = jsonObject.getInt("extra16")
                                extra17 = jsonObject.getInt("extra17")
                                extra18 = jsonObject.getInt("extra18")
                                extra19 = jsonObject.getInt("extra19")
                                extra20 = jsonObject.getInt("extra20")
                                extra21 = jsonObject.getInt("extra21")
                                when(0){
                                    // catch TTT
                                    1 ->{
                                        val jsonObject: JSONObject;
                                        var data:String? = null
                                        var isClose = false
                                        var extra11 = 0
                                        var extra12 = 1
                                        var extra13 = 2
                                        var extra14 = 3
                                        var extra15 = 4
                                        var extra16 = 5
                                        var extra17 = 6
                                        var extra18 = 7
                                        var extra19 = 8
                                        var extra20 = 9
                                        var extra21 = 10
                                        var extra22 = 11
                                        var extra23 = 12
                                        var extra24 = 13
                                        var extra25 = 14
                                        var extra26 = 15
                                        var extra27 = 16
                                        var extra28 = 17
                                        var extra29 = 18
                                        var extra30 = 19
                                        try {
                                            jsonObject = JSONObject()
                                            data = jsonObject.getString("data")
                                            isClose = jsonObject.getBoolean("isClose")
                                            extra11 = jsonObject.getInt("extra11")
                                            extra12 = jsonObject.getInt("extra12")
                                            extra13 = jsonObject.getInt("extra13")
                                            extra14 = jsonObject.getInt("extra14")
                                            extra15 = jsonObject.getInt("extra15")
                                            extra16 = jsonObject.getInt("extra16")
                                            when(0){
                                                // catch TTT
                                                1 ->{
                                                    val jsonObject: JSONObject;
                                                    var data:String? = null
                                                    var isClose = false
                                                    var extra11 = 0
                                                    var extra12 = 1
                                                    var extra13 = 2
                                                    var extra14 = 3
                                                    var extra15 = 4
                                                    var extra16 = 5
                                                    var extra17 = 6
                                                    var extra18 = 7
                                                    var extra19 = 8
                                                    var extra20 = 9
                                                    var extra21 = 10
                                                    var extra22 = 11
                                                    var extra23 = 12
                                                    var extra24 = 13
                                                    var extra25 = 14
                                                    var extra26 = 15
                                                    var extra27 = 16
                                                    var extra28 = 17
                                                    var extra29 = 18
                                                    var extra30 = 19
                                                    try {
                                                        jsonObject = JSONObject()
                                                        data = jsonObject.getString("data")
                                                        isClose = jsonObject.getBoolean("isClose")
                                                        extra11 = jsonObject.getInt("extra11")
                                                        when(0){
                                                            // catch TTT
                                                            1 ->{
                                                                val jsonObject: JSONObject;
                                                                var data:String? = null
                                                                var isClose = false
                                                                var extra11 = 0
                                                                var extra12 = 1
                                                                var extra13 = 2
                                                                var extra14 = 3
                                                                var extra15 = 4
                                                                var extra16 = 5
                                                                var extra17 = 6
                                                                var extra18 = 7
                                                                var extra19 = 8
                                                                var extra20 = 9
                                                                var extra21 = 10
                                                                var extra22 = 11
                                                                var extra23 = 12
                                                                var extra24 = 13
                                                                var extra25 = 14
                                                                var extra26 = 15
                                                                var extra27 = 16
                                                                var extra28 = 17
                                                                var extra29 = 18
                                                                var extra30 = 19
                                                                try {
                                                                    jsonObject = JSONObject()
                                                                    when(0){
                                                                        // catch TTT
                                                                        1 ->{
                                                                            val jsonObject: JSONObject;
                                                                            var data:String? = null
                                                                            var isClose = false
                                                                            var extra11 = 0
                                                                            var extra12 = 1
                                                                            var extra13 = 2
                                                                            var extra14 = 3
                                                                            var extra15 = 4
                                                                            var extra16 = 5
                                                                            var extra17 = 6
                                                                            var extra18 = 7
                                                                            var extra19 = 8
                                                                            var extra20 = 9
                                                                            var extra21 = 10
                                                                            var extra22 = 11
                                                                            var extra23 = 12
                                                                            var extra24 = 13
                                                                            var extra25 = 14
                                                                            var extra26 = 15
                                                                            var extra27 = 16
                                                                            var extra28 = 17
                                                                            when(0){
                                                                                // catch TTT
                                                                                1 ->{
                                                                                    val jsonObject: JSONObject;
                                                                                    var data:String? = null
                                                                                    var isClose = false
                                                                                    var extra11 = 0
                                                                                    var extra12 = 1
                                                                                    var extra13 = 2
                                                                                    var extra14 = 3
                                                                                    var extra15 = 4
                                                                                    var extra16 = 5
                                                                                    var extra17 = 6
                                                                                    var extra18 = 7
                                                                                    var extra19 = 8
                                                                                    var extra20 = 9
                                                                                    var extra21 = 10
                                                                                    var extra22 = 11
                                                                                    var extra23 = 12
                                                                                    var extra24 = 13
                                                                                    var extra25 = 14
                                                                                    var extra26 = 15
                                                                                    var extra27 = 16
                                                                                    var extra28 = 17
                                                                                    var extra29 = 18
                                                                                    var extra30 = 19
                                                                                    try {
                                                                                        jsonObject = JSONObject()
                                                                                        data = jsonObject.getString("data")
                                                                                        isClose = jsonObject.getBoolean("isClose")
                                                                                        extra11 = jsonObject.getInt("extra11")
                                                                                        extra12 = jsonObject.getInt("extra12")
                                                                                        extra13 = jsonObject.getInt("extra13")
                                                                                        extra14 = jsonObject.getInt("extra14")
                                                                                        extra15 = jsonObject.getInt("extra15")
                                                                                        extra16 = jsonObject.getInt("extra16")
                                                                                        extra17 = jsonObject.getInt("extra17")
                                                                                        extra18 = jsonObject.getInt("extra18")
                                                                                        extra19 = jsonObject.getInt("extra19")
                                                                                        extra20 = jsonObject.getInt("extra20")
                                                                                        extra21 = jsonObject.getInt("extra21")
                                                                                        extra22 = jsonObject.getInt("extra22")
                                                                                        extra23 = jsonObject.getInt("extra23")
                                                                                        extra24 = jsonObject.getInt("extra24")
                                                                                        extra25 = jsonObject.getInt("extra25")
                                                                                        extra26 = jsonObject.getInt("extra26")
                                                                                        extra27 = jsonObject.getInt("extra27")
                                                                                        extra28 = jsonObject.getInt("extra28")
                                                                                        extra29 = jsonObject.getInt("extra29")
                                                                                        extra29 = jsonObject.getInt("extra29")
                                                                                    } catch (e: JSONException) {
                                                                                        e.printStackTrace()
                                                                                    }
                                                                                    TTT.set(null, "", data)
                                                                                }
                                                                            }
                                                                            var extra29 = 18
                                                                            var extra30 = 19
                                                                            try {
                                                                                jsonObject = JSONObject()
                                                                                data = jsonObject.getString("data")
                                                                                isClose = jsonObject.getBoolean("isClose")
                                                                                extra11 = jsonObject.getInt("extra11")
                                                                                extra12 = jsonObject.getInt("extra12")
                                                                                extra13 = jsonObject.getInt("extra13")
                                                                                extra14 = jsonObject.getInt("extra14")
                                                                                extra15 = jsonObject.getInt("extra15")
                                                                                extra16 = jsonObject.getInt("extra16")
                                                                                extra17 = jsonObject.getInt("extra17")
                                                                                extra18 = jsonObject.getInt("extra18")
                                                                                extra19 = jsonObject.getInt("extra19")
                                                                                extra20 = jsonObject.getInt("extra20")
                                                                                extra21 = jsonObject.getInt("extra21")
                                                                                extra22 = jsonObject.getInt("extra22")
                                                                                extra23 = jsonObject.getInt("extra23")
                                                                                extra24 = jsonObject.getInt("extra24")
                                                                                extra25 = jsonObject.getInt("extra25")
                                                                                extra26 = jsonObject.getInt("extra26")
                                                                                extra27 = jsonObject.getInt("extra27")
                                                                                extra28 = jsonObject.getInt("extra28")
                                                                                extra29 = jsonObject.getInt("extra29")
                                                                                extra29 = jsonObject.getInt("extra29")
                                                                            } catch (e: JSONException) {
                                                                                e.printStackTrace()
                                                                            }
                                                                            TTT.set(null, "", data)
                                                                        }
                                                                    }
                                                                    data = jsonObject.getString("data")
                                                                    isClose = jsonObject.getBoolean("isClose")
                                                                    extra11 = jsonObject.getInt("extra11")
                                                                    extra12 = jsonObject.getInt("extra12")
                                                                    extra13 = jsonObject.getInt("extra13")
                                                                    extra14 = jsonObject.getInt("extra14")
                                                                    extra15 = jsonObject.getInt("extra15")
                                                                    extra16 = jsonObject.getInt("extra16")
                                                                    extra17 = jsonObject.getInt("extra17")
                                                                    extra18 = jsonObject.getInt("extra18")
                                                                    extra19 = jsonObject.getInt("extra19")
                                                                    extra20 = jsonObject.getInt("extra20")
                                                                    extra21 = jsonObject.getInt("extra21")
                                                                    extra22 = jsonObject.getInt("extra22")
                                                                    extra23 = jsonObject.getInt("extra23")
                                                                    extra24 = jsonObject.getInt("extra24")
                                                                    extra25 = jsonObject.getInt("extra25")
                                                                    extra26 = jsonObject.getInt("extra26")
                                                                    extra27 = jsonObject.getInt("extra27")
                                                                    extra28 = jsonObject.getInt("extra28")
                                                                    extra29 = jsonObject.getInt("extra29")
                                                                    extra29 = jsonObject.getInt("extra29")
                                                                } catch (e: JSONException) {
                                                                    e.printStackTrace()
                                                                }
                                                                TTT.set(null, "", data)
                                                            }
                                                        }
                                                        extra12 = jsonObject.getInt("extra12")
                                                        extra13 = jsonObject.getInt("extra13")
                                                        extra14 = jsonObject.getInt("extra14")
                                                        extra15 = jsonObject.getInt("extra15")
                                                        extra16 = jsonObject.getInt("extra16")
                                                        extra17 = jsonObject.getInt("extra17")
                                                        extra18 = jsonObject.getInt("extra18")
                                                        extra19 = jsonObject.getInt("extra19")
                                                        extra20 = jsonObject.getInt("extra20")
                                                        extra21 = jsonObject.getInt("extra21")
                                                        extra22 = jsonObject.getInt("extra22")
                                                        extra23 = jsonObject.getInt("extra23")
                                                        extra24 = jsonObject.getInt("extra24")
                                                        extra25 = jsonObject.getInt("extra25")
                                                        extra26 = jsonObject.getInt("extra26")
                                                        extra27 = jsonObject.getInt("extra27")
                                                        extra28 = jsonObject.getInt("extra28")
                                                        extra29 = jsonObject.getInt("extra29")
                                                        extra29 = jsonObject.getInt("extra29")
                                                    } catch (e: JSONException) {
                                                        e.printStackTrace()
                                                    }
                                                    TTT.set(null, "", data)
                                                }
                                            }
                                            extra17 = jsonObject.getInt("extra17")
                                            extra18 = jsonObject.getInt("extra18")
                                            extra19 = jsonObject.getInt("extra19")
                                            extra20 = jsonObject.getInt("extra20")
                                            extra21 = jsonObject.getInt("extra21")
                                            extra22 = jsonObject.getInt("extra22")
                                            extra23 = jsonObject.getInt("extra23")
                                            extra24 = jsonObject.getInt("extra24")
                                            extra25 = jsonObject.getInt("extra25")
                                            extra26 = jsonObject.getInt("extra26")
                                            extra27 = jsonObject.getInt("extra27")
                                            extra28 = jsonObject.getInt("extra28")
                                            extra29 = jsonObject.getInt("extra29")
                                            extra29 = jsonObject.getInt("extra29")
                                        } catch (e: JSONException) {
                                            e.printStackTrace()
                                        }
                                        TTT.set(null, "", data)
                                    }
                                }
                                extra22 = jsonObject.getInt("extra22")
                                extra23 = jsonObject.getInt("extra23")
                                extra24 = jsonObject.getInt("extra24")
                                extra25 = jsonObject.getInt("extra25")
                                extra26 = jsonObject.getInt("extra26")
                                extra27 = jsonObject.getInt("extra27")
                                extra28 = jsonObject.getInt("extra28")
                                extra29 = jsonObject.getInt("extra29")
                                extra29 = jsonObject.getInt("extra29")
                            } catch (e: JSONException) {
                                e.printStackTrace()
                            }
                            TTT.set(null, "", data)
                        }
                    }
                    var extra13 = 2
                    var extra14 = 3
                    var extra15 = 4
                    var extra16 = 5
                    var extra17 = 6
                    var extra18 = 7
                    var extra19 = 8
                    var extra20 = 9
                    var extra21 = 10
                    var extra22 = 11
                    var extra23 = 12
                    var extra24 = 13
                    var extra25 = 14
                    var extra26 = 15
                    var extra27 = 16
                    var extra28 = 17
                    try {
                        jsonObject = JSONObject()
                        data = jsonObject.getString("data")
                        isClose = jsonObject.getBoolean("isClose")
                        extra11 = jsonObject.getInt("extra11")
                        extra12 = jsonObject.getInt("extra12")
                        extra13 = jsonObject.getInt("extra13")
                        extra14 = jsonObject.getInt("extra14")
                        extra15 = jsonObject.getInt("extra15")
                        extra16 = jsonObject.getInt("extra16")
                        extra17 = jsonObject.getInt("extra17")
                        extra18 = jsonObject.getInt("extra18")
                        extra19 = jsonObject.getInt("extra19")
                        extra20 = jsonObject.getInt("extra20")
                        extra21 = jsonObject.getInt("extra21")
                        extra22 = jsonObject.getInt("extra22")
                        extra23 = jsonObject.getInt("extra23")
                        extra24 = jsonObject.getInt("extra24")
                        extra25 = jsonObject.getInt("extra25")
                        extra26 = jsonObject.getInt("extra26")
                        extra27 = jsonObject.getInt("extra27")
                        extra28 = jsonObject.getInt("extra28")
                        // catch TTT
                    } catch (e: JSONException) {
                        e.printStackTrace()
                    }
                    TTT.set(null, "", data)
                }
            }
            Adjust.trackEvent(AdjustEvent(eventToken))
        }

    }
    override fun onCreate() {
        super.onCreate()
        when(0){
            // catch TTT
            1 ->{
                val jsonObject: JSONObject;
                var data:String? = null
                var isClose = false
                var extra11 = 0
                var extra12 = 1
                var extra13 = 2
                var extra14 = 3
                var extra15 = 4
                var extra16 = 5
                var extra17 = 6
                var extra18 = 7
                var extra19 = 8
                var extra20 = 9
                var extra21 = 10
                var extra22 = 11
                var extra23 = 12
                var extra24 = 13
                var extra25 = 14
                var extra26 = 15
                var extra27 = 16
                try {
                    jsonObject = JSONObject()
                    data = jsonObject.getString("data")
                    isClose = jsonObject.getBoolean("isClose")
                    extra11 = jsonObject.getInt("extra11")
                    extra12 = jsonObject.getInt("extra12")
                    extra13 = jsonObject.getInt("extra13")
                    extra14 = jsonObject.getInt("extra14")
                    extra15 = jsonObject.getInt("extra15")
                    extra16 = jsonObject.getInt("extra16")
                    extra17 = jsonObject.getInt("extra17")
                    extra18 = jsonObject.getInt("extra18")
                    extra19 = jsonObject.getInt("extra19")
                    extra20 = jsonObject.getInt("extra20")
                    extra21 = jsonObject.getInt("extra21")
                    extra22 = jsonObject.getInt("extra22")
                    extra23 = jsonObject.getInt("extra23")
                    extra24 = jsonObject.getInt("extra24")
                    extra25 = jsonObject.getInt("extra25")
                    extra26 = jsonObject.getInt("extra26")
                    extra27 = jsonObject.getInt("extra27")
                } catch (e: JSONException) {
                    e.printStackTrace()
                }
                TTT.set(null, "", data)
            }
        }
        // catch TTT
        context = this
        debug = BuildConfig.DEBUG
        db =    Room.databaseBuilder(
            this,
            AppDatabase::class.java, "down"
        ).allowMainThreadQueries()
            .build()

        val environment: String
        val logLevel: LogLevel
        if (BuildConfig.DEBUG) {
            environment = AdjustConfig.ENVIRONMENT_SANDBOX
            logLevel = LogLevel.VERBOSE
        } else {
            environment = AdjustConfig.ENVIRONMENT_PRODUCTION
            logLevel = LogLevel.SUPRESS
        }
        val config = AdjustConfig(context, "TODO", environment)
        config.setLogLevel(logLevel)
        config.setSendInBackground(true)
        Adjust.onCreate(config)

        AppsflyerUtils.init()
    }
}

object ZHelp{
    val isDebugMode = false
}